Part Number Hot Search : 
S2405 2F5081 DD500 3A010 FM303L SR4001PT MPX2050D B45NF3
Product Description
Full Text Search
 

To Download AN1298 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  1/9 author: n. abbate september 2000 AN1298 application note pid controller using st52x420 mcu 1. introduction intention of this application note is to explain the implementation of a pid controller using the st52x420 microcontroller. pids have a fundamental importance in the industrial controller field, for the simplicity of approach, the robustness of control and the immediacy of calibration. pid controller is a typology of regulator that implements proportional, integral and derivative action. in fig.1 is shown the control loop of a standard pid regulator. figure 1. control loop in this regulator, the variable aerroro , the derivative and the integral errors are performed to calculate the output variable u(t) , function of the above. the pid algorithm is given by: where k p , k i , k d are pid gain constants, u(t) is control signal and e(t) is error signal. to convert to discrete form, the integral term is approximated with , where t is the sampling interval and e i is the value of the error signal at sample time i , written as : i e p i d et d d e d t ----- error(t) sensor(t) reference s u(t) () () t e d k edt i k t e p k t u ? ? + + = et d s e i t et d s e i t @
AN1298 - application note 2/9 if the sampling time is smaller, the differential term can be approximated like where e(n) and e(n-1) are values of the error signal e at time intervals n and n-1 . the pid algorithm can now be approximated in discrete form by: in this form it is simpler to implement an algorithm. the constants k(p,i,d) can be designed using various methods such as ziegler nichols, phase margin, critical frequencies, heuristic etc. the choice between these techniques depends on the type of application because it is extremely different to implement a pid regulator in a system where only the mathematical models is known (i.e. transfer's function), or in a non-linear system, where only input/output measures are possible. a brief overview to some of the effects linked to the influence of proportional, integral or derivative action is shown in the following paragraph. 2. influence of pid parameter three are the parameters that influence the performances of a pid controller: proportional integral and derivative constants. each one has a different impact on the system and an appropriate mix of these three parameters provides a good regulator. however, it is not necessary to use all the parameters at the same time. proportional actions express the control action proportional to the error. this is very efficient to reduce ex- ternal noise and disturbance in our system and guarantee stability of closed loop. integral action is essential to make sure that the process output agrees with the set point in steady state. derivative action may be interpreted as if the control is made proportional to the forecasted process out- put, where the prediction is made by extrapolating the error by the tangent to the error curve. another main parameter is the aintegration timeo, but this is already inside the pid regulator. extremely important is the wind-up of integral action. when a large error is present in the system, for in- stance when a large step disturbance is encountered, the integrator continually builds up even though the output is saturated. this condition is called owind upo. when the system exits from this condition, the inte- grator ounwindso causing excessive oscillation. this integral pid implementation avoids this problem by stopping the action of the integrator during output variable duty saturation. 3. pid implementation st52x420 has on-chip hardware multiplication between two bytes. this functionality is very important for the correct flow of the algorithm, because the variable error, created from difference between encoder and reference signals in an apposite folder called a encoder o, is manipulated by the pid regulator to generate the output control signal mainly using multiplication. fuzzystudio ? 4 development tool allows to design the regulator in a simple way. the main block of the controller is an alu block called pid, where the input variable is manipulated and stored, to create the signed-byte control variable appsbyte that increments or decrements the value of the control variable duty . the instruction set of st52x420 allows to use different types of variables: word, signed-byte, word and byte. the problem consists in translating the information content in a multiplication between signed-byte and constants (obtaining signed-word variable) in a signed-byte variable. this operation is executed using a scaling between the variable aincremento (signed-word), using only the high side of double byte that represents the signed-word, and reduce this quantity of a value correspond- ing to 128; the result is stored in a signed-byte variable. d e d t ----- d e d t ----- en () en 1 () t ------------------------------------ @ un () k p en () k i s e i tk d en () en 1 () t ------------------------------------ ++ =
3/9 AN1298 - application note 4. functional description in this application, an external encoder acquires the angular speed of an asynchronous motor. after the acquisition, and the appropriate conditioning, the signal is stored in the variable speed . this action has been performed with an appropriate procedure called encoder . figure 2. speed acquisition task inside the interrupt routine of the pwm1 peripheral, a counter is used to modify the sampling time of reg- ulator, to define the opportune integration time for each application. so the real regulator's time loop vary from 50 m sto50 m s*counter [byte/word] with an incremental software loop. the control sampling time is synchronized with 20khz pwm of timer_1 peripheral, employed to supply the asynchronous motor with a patented board. figure 3. pwm configuration t t encoder (external timer) speed stop speed start pid counter
AN1298 - application note 4/9 figure 4. interrupt routine apwm1o in fuzzystudio tm 4 implementation in each control's step, the variable called error (signed-byte), is computed and manipulated to perform the appropriate control law with the following procedure: ? the acquired signal speed is compared now with the requested reference ref and the difference is stored in the variable called aerroro . ? an underflow/overflow control is actuated using the preset fuzzystudio ? 4 function. ? a variable called apropo implements the proportional action, multiplying the error by the constant k p . this constant is representative of the proportional pid parameter so like k i and k d represents respectively the integral and the derivative parameters, set like constants in fuzzystudio ? 4. ? the integral action is achieved updating the variable integral adding the current value of a error o; after the overflow/underflow control, the variable a integ o is computed like ki*error [signed-word]. in this firmware an integrator anti-windup has already been implemented thus avoiding the wind-up problem by stopping the action of the integrator when the output variable a duty a is saturated. ? the derivative action is obtained calculating the difference between the current and the previous step a erroro (error_old) . the result is multiplied by kd to obtain the signed-word a der o. ? the actual value of a error o to be used in the next step is stored in a support variable called aerror_old o. ? after this phase, summing the quantity above, we obtain a signed-word variable called a increment o. now, we need to scale them in a signed-byte with an opportune algorithm to maintain the 16-bit information content in an 8-bit signed variable. so we use a variable called a appsbyte o to perform an increment or a decrement of the output control variable (precisely the duty cycle of the 20 khz pwm).
5/9 AN1298 - application note in the following figure is represented the alu block inside the firmware that controls the washing ma- chine's motor. in fuzzystudio ? 4 the alu blocks allow to design a firmware in a oco-like coding, with powerful dedi- cated functions to manipulate byte, word, signed, under/overflow control, peripherals' setting, mathemat- ical functions, variable assignation and more. figure 5. alu blockopid_regulatoro in fuzzystudio tm 4 implementation 5. results and conclusion this application shows a simple way to implement a pid controller with the st52x420 micro. using this approach it is possible to obtain a regulator with performances suited to the application, calibrating the typology of control action in function of the system. the strategy of calibration has not been treated here, but in reference [1] various techniques are discussed in depth. the following figures show the performances of a washing machine motor's regulator in start-up condition, changing speed reference on-fly and load variation. this acquisition performed with an on-board serial communication software, represents the comparison between the simultaneous input speed and output duty-cycle of the asynchronous motor driver. the tar- gets achieved are: 1. reach the reference speed. 2. noise and error disturbance reduction. 3. low employment of the micro resources to allow other applications' functionalities.
AN1298 - application note 6/9 figure 6. start-up figure 7. change reference with anti-wind-up action 0 50 100 150 200 250 0123456 time [s] speed/duty cycle duty cycle speed ref. 0 50 100 150 200 250 024681012141618202224262830323436 time [s] speed /duty cycle duty cycle speed
7/9 AN1298 - application note figure 8. step stimulus and load variation references [1] k.j. ?str?m, t. h?gglund o pid controllers o, 2nd edition, instrument society of america 1995. [2] fuzzystudio ? 4.0 user manual, stmicroelectronics 2000 0 50 100 150 200 250 300 0 0,9 1,8 2,7 3,6 4,5 5,4 6,3 7,2 8,1 9 9,9 10,8 11,7 12,6 13,5 14,4 15,3 16,2 17,1 18 18,9 19,8 20,7 21,6 22,5 23,4 24,3 25,2 26,1 27 27,9 28,8 29,7 30,6 31,5 32,4 33,3 34,2 35,1 36 time [s] speed / duty cycle duty cycle speed ref. start external perturbation (step disturbance) start external perturbation (constant over-load)
AN1298 - application note 8/9 appendix: st52 fs code //***********************init*************** error=rif-speed; //actual error=reference-actual speed acquisition if(isoverflow()) error=127; //error saturation else if(isunderflow()) error=-128; //********** proportional action**************** prop=kp*error; //sword variable=costant*sbyte variable //************** end_proportional action ****************** //************** integral action ************************** if(duty<=255) //integral action with anti-windup {integral=integral+error; //actualisation of integral factor if(isoverflow()) integral=127; //saturation of signed byte variable else if (isunderflow()) integral=-128 }; integ=ki*integral; //sword=costant*sbyte //**************** end_integral action******************** //******************** derivative action ***************** derivative=error-error_old; //actualisation of derivative component if(isoverflow()) derivative=127; //saturation of signed byte variable else if (isunderflow()) derivative=-128; der=kv*derivative; //*************** end_derivative action ****************** error_old=error; //store actual error for next control step //*************** scaling 16bit-->8bit ******************* increment=prop+integ; //sum of component integral and proportional increment=increment+der; //sum of component derivative appsbyte=increment.high-128; //from sword variable to signed byte variable with scaling if(isoverflow()) appsbyte=127; //saturation of signed byte variable else if (isunderflow()) appsbyte=-128; //******* compute of actual output variable odutyo ******** duty=duty+appsbyte; //actual duty previous duty+actual output control variable if(isoverflow()) duty=255; //output variable running from 0 to 255 else if (isunderflow()) duty =0; //******************* end of pid regulator *************
9/9 AN1298 - application note information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specification mentioned in this publication are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of stmicroelectronics. the st logo is a trademark of stmicroelectronics ? 2000 stmicroelectronics - all rights reserved fuzzystudio tm is a registered trademark of stmicroelectronics stmicroelectronics group of companies http://www.st.com australia - brazil - china - finland - france - germany - hong kong - india - italy - japan - malaysia - malta - morocco- singapore - spain - sweden - switzerland - united kingdom - u.s.a.


▲Up To Search▲   

 
Price & Availability of AN1298

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X